// export const baseURL = 'http://61.182.254.18:9150';//线上接口地址，图片拼接地址
export const baseURL = 'http://localhost:8080';//线上接口地址，图片拼接地址


export function request(params={}){
  
  let dataObj = params.data;
  let userInfo = wx.getStorageSync("userInfo")
  let headerObj = {
    'content-type': 'application/json',
    "Authorization" : `Bearer ${userInfo.token}`
  }
  
  return new Promise((resolve,reject)=>{
    wx.request({
      url: baseURL + params.url,
      method:params.method || "GET",
      data:dataObj,
      header:headerObj,
      success:res=>{
        // console.log(res);
        if(res.data.code == 200){
          resolve(res.data)
          return;
        }else if(res.data.code==401){
          wx.showModal({
            title: '系统提示',
            content: '登陆已过期，重新登录',
            showCancel:false,
            complete: (res) => {
              if (res.confirm) {
                wx.removeStorageSync('userInfo')
                  wx.reLaunch({
                    url: '../pages/login/login',
                  })
              }
            }
          })
        }else{
          reject(res)
        }
        
      },
      fail:err=>{
        reject(err)
      }
    })
  })
}

